import { useContext, createContext } from "react";
const Context = createContext() // 创建上下文对象

function Bar() {
  const val = useContext(Context) // 获取老一辈辈组件传来的值
  return  (
    <div>
      <h3>bar --  {val}</h3>
    </div>
  )
}

function Foo() {
  return (
    <div>
      <h2>foo</h2>
      <Bar />
    </div>
  )
}

function App() {
  return (
    <Context.Provider value={'来自app'}>
      <div>
        <h1>app</h1>
        <Foo />
      </div>
    </Context.Provider>
  )
}

export default App;